<%@page import="java.util.Date"%>
<%@page import="java.util.List"%>
<%@page import="org.zty.service.PojoService"%>
<%@page import="org.zty.domain.Pojo"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="common/taglib.jsp" %>
<%@include file="common/page.jsp" %>
<%

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${projectName}</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<%@include file="common/js_css.jsp" %>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<style>
form {
	margin: 0px;
	padding: 0px;
}

input {
	border: 1px solid #cecece;
	color: #3b6998;
	font-size: 14px;
	line-height: 26px;
	height: 26px;
	width: 240px;
	margin-left: 15px;
}
</style>
<script>
function addInput(tmp){
	console.log($(tmp))
	var index = $(tmp).attr("attr");
	var newIndex = parseInt(index)+1;
	if($("#"+newIndex).length>0){
		console.log($(tmp));
	}else{
		$("#attr_table tbody").append("<tr id=\""+newIndex+"\"><td>"+newIndex+"</td><td><input type=\"text\" name=\"attr_type\" class=\"attr_type\" onblur=\"fillInput(this)\" /></td><td><input attr=\""+newIndex+"\" type=\"text\" name=\"attr_name\" class=\"attr_name\" onfocus=\"addInput(this)\"/></td></tr>");	
	}
}
function fillInput(tmp){
	var val = $(tmp).val().toLowerCase();
	if(val=="i"){
		$(tmp).val("int");
	}
	if(val=="s"){
		$(tmp).val("String");
	}
	if(val=="d"){
		$(tmp).val("Date");
	}
}

var isctrl = false;
function savePojo(){
	if(!isctrl){
		isctrl=true;
		$.ajax({
			url:"pojo_do.jsp",
			cache:false,
			type : 'GET',
			dataType : "json",
			data:$("#form1").serialize(),
			success:function(data){
				isctrl=false;
			}
		});
	}
	
}
</script>
</head>

<body>
	<form action="code_do.jsp" id="form1" name="form1" method="post" target="_blank">
		<input type="hidden" value="add" name="m"/>
		类名<input name="pojo_name" type="text"/><br/>
		备注	<input type="text" name="descstr" id="descstr" value=""/>
		<table id="attr_table">
			<thead>
				<tr>
					<td align="center">序号</td><td align="center">类型</td><td align="center">属性名</td>
				</tr>
			</thead>
			<tbody>
				<tr id="1">
					<td>1</td>
					<td><input type="text" name="attr_type" class="attr_type" onblur="fillInput(this)"/></td>
					<td><input attr="1" type="text" name="attr_name" class="attr_name" onfocus="addInput(this)"/></td>
				</tr>
			</tbody>
		</table>
		
		<div class="form_bt_block" style="width:310px;position:relative;">
			<div title="" class="function_block function_block_c1 fleft" style="margin-left:10px;height:80px;width:180px;" onclick="form1.submit()">
				<div class="function_block_text">输出代码</div>
				<div class="function_block_pic" style="height:34px;width:44px;background-position:-64px -127px;"></div>
			</div>
			<div title="" class="function_block function_block_c6 fleft" style="margin-left:10px;height:80px;width:110px;" onclick="savePojo();">
				<div class="function_block_text">保存到数据库</div>
				<div class="function_block_pic" style="height:44px;width:34px;"></div>
			</div>
		</div>
	</form>

</body>
</html>
